<?php
N::loadClass('APP_Controller_Base');
Class APP_Controller_Index extends APP_Controller_Base
{
	/**
	 * 直接包含文件
	 *
	 */
	public function actionIndex()
	{
		$tplRoot = N::getIni('TPL_ROOT');
		include($tplRoot.'/index-tpl.php');
	}
	
	/**
	 * Smarty模式使用示范
	 *
	 */
	public function actionSmarty()
	{
		//Smarty使用示范,由于index.php文件已经配置使用smarty,所以可以直接调用_getView方法返回view实例
		$view = $this->_getView();
		//$view = new Smarty(...$params...);效果同上
		$view->assign("title", "Smarty使用示范");
		$view->assign("content", "Test Index");
		$view->display("smarty.html");
	}
	
	/**
	 * nphp内置默认使用pdo作为数据库连接层
	 *
	 */
	public function actionPdo()
	{
		$model = $this->_getModel();
		$ps = $model->query("select * from n_example");
		foreach ($ps as $row)
		{
			echo "username:".$row['name'].' | password:'.$row['passwd'].'<br>';
		}
	}
	
	/**
	 * 使用内置的DB类,默认是PDO
	 *
	 */
	public function actiondb()
	{
		$db = N::getSingleton(N::getIni('DB'));
		$ps = $db->query("select * from n_example");
		foreach ($ps as $row)
		{
			echo "username:".$row['name'].' | password:'.$row['passwd'].'<br>';
		}
	}
	
	/**
	 * Model层使用示范
	 *
	 */
	public function actionModel()
	{
		$model = $this->_getModel();
		$ps = $model->getAllUser();
		foreach ($ps as $row)
		{
			echo "username:".$row['name'].' | password:'.$row['passwd'].'<br>';
		}
	}
}